package com.hq.shcrm.service.Impl;

import com.hq.shcrm.mapper.TCourseOrderMapper;
import com.hq.shcrm.pojo.MonthIncome;
import com.hq.shcrm.pojo.PageResult;
import com.hq.shcrm.pojo.TCourseOrder;
import com.hq.shcrm.pojo.TCourseOrderExample;
import com.hq.shcrm.service.ICourceOrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class ICourseOrderServiceImpl implements ICourceOrderService {

    @Autowired
    private TCourseOrderMapper tCourseOrderMapper;

    @Override
    public PageResult<TCourseOrder> findPageResult(TCourseOrder condition, int page, int pageSize) {

        //定义一个Map-参数先不放在map,后面再处理
        Map<String,Object> params = new HashMap<>();
        params.put("condition",condition);
        params.put("start",(page-1)*pageSize);
        params.put("pageSize",pageSize);

        TCourseOrderExample example = new TCourseOrderExample();

        //定义结果
        PageResult<TCourseOrder> result = new PageResult<>();

        result.setCount(tCourseOrderMapper.findCountByMap(params));
        result.setData(tCourseOrderMapper.findListByMap(params));
        return result;

    }

    @Override
    public void save(TCourseOrder courseOrder) {
        tCourseOrderMapper.insert(courseOrder);
    }

    @Override
    public TCourseOrder findbyOrderId(String order_id) {
        return tCourseOrderMapper.findbyOrderId(order_id);
    }

    @Override
    public void deletebyOrderId(String order_id) {
        tCourseOrderMapper.deleteByOrderId(order_id);
    }

    @Override
    public void update(TCourseOrder order) {
        tCourseOrderMapper.updateByOrderId(order);
    }

    @Override
    public List<MonthIncome> getMonthIncomes() {
        return tCourseOrderMapper.getMonthIncomes();
    }
}
